package dp.ua.epic.resource;

import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.wicket.Component;
import org.apache.wicket.resource.loader.IStringResourceLoader;

/**
 * Provide bundle loading from non standart directory
 * @author Chris
 * @date 03.02.2011 13:26:55
 */
public class ExternalResourceLoader implements IStringResourceLoader {

    private String resourceBundleName;

    public ExternalResourceLoader(String resourceBundleName) {
        this.resourceBundleName = resourceBundleName;
    }

    @Override
    public String loadStringResource(Component component, String key) {
        return findResource(component.getLocale(), key);
    }

    @Override
    public String loadStringResource(Class<?> clazz, String key, Locale locale, String style) {
        return findResource(locale, key);
    }

    private String findResource(Locale locale, String key) {
        return ResourceBundle.getBundle(resourceBundleName, locale).getString(key);
    }
}
